<script lang="ts" setup>
  const data = [
    {
      name: '团队审核',
      type: 'custom-vue-node',
      icon: '👥',
      properties: {
        borderColor: '#EA8622',
        auditTime: null,
        userId: [],
        value: 'team',
      },
    },
    {
      name: '部门审核',
      type: 'custom-vue-node',
      icon: '🏢',
      properties: {
        borderColor: '#229DEA',
        auditTime: null,
        userId: [],
        value: 'dept',
      },
    },
    {
      name: '学校审核',
      type: 'custom-vue-node',
      icon: '🏫',
      properties: {
        borderColor: '#22EA29',
        auditTime: null,
        userId: [],
        value: 'school',
      },
    },
    {
      name: '自定义审核',
      type: 'custom-vue-node',
      icon: '⚡',
      properties: {
        borderColor: '#8622EA',
        auditTime: null,
        userId: [],
        value: 'auto',
      },
    },
  ]

  // 获取节点描述
  const getNodeDescription = (value: string) => {
    const descriptions = {
      team: '团队内部审核流程',
      dept: '系部级别审核流程',
      school: '学校级别审核流程',
      auto: '自定义审核流程',
    }
    return descriptions[value] || '审核流程节点'
  }

  // 鼠标悬浮事件
  const handleMouseEnter = (event: MouseEvent, item: any) => {
    const card = (event.currentTarget as HTMLElement).querySelector('.node-card') as HTMLElement
    if (card) {
      const color = item.properties.borderColor
      card.style.background = color + '10' // 10% 透明度
      card.style.borderColor = color
      card.style.boxShadow = `0 4px 12px ${color}25` // 25% 透明度
    }
  }

  const handleMouseLeave = (event: MouseEvent, item: any) => {
    const card = (event.currentTarget as HTMLElement).querySelector('.node-card') as HTMLElement
    if (card) {
      card.style.background = '#ffffff'
      card.style.borderColor = '#e8e8e8'
      card.style.boxShadow = 'none'
    }
  }

  // 拖拽开始事件
  const handleDragStart = (event: DragEvent, item: any) => {
    if (event.dataTransfer) {
      // 设置拖拽数据
      event.dataTransfer.setData(
        'application/json',
        JSON.stringify({
          type: item.type,
          text: item.name,
          properties: item.properties || {},
        }),
      )
      event.dataTransfer.effectAllowed = 'copy'
    }
  }
</script>
<template>
  <div class="panel-container">
    <div class="panel-header">
      <div class="header-title">
        <svg class="header-icon" viewBox="0 0 1024 1024" width="16" height="16">
          <path
            d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"
            fill="currentColor"
          />
          <path
            d="M464 336a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"
            fill="currentColor"
          />
        </svg>
        <span>节点面板</span>
      </div>
      <div class="header-subtitle">拖拽节点到画布中添加</div>
    </div>

    <div class="panel-content">
      <div class="node-category">
        <div class="node-list">
          <div
            v-for="(item, index) in data"
            :key="index"
            class="node-item"
            draggable="true"
            @dragstart="handleDragStart($event, item)"
            @mouseenter="handleMouseEnter($event, item)"
            @mouseleave="handleMouseLeave($event, item)"
          >
            <div class="node-card">
              <div class="node-icon-wrapper">
                <div class="node-icon" :style="{ backgroundColor: item.properties.borderColor + '20', color: item.properties.borderColor }">
                  {{ item.icon }}
                </div>
              </div>
              <div class="node-content">
                <div class="node-title">{{ item.name }}</div>
                <div class="node-desc">{{ getNodeDescription(item.properties.value) }}</div>
              </div>
              <div class="drag-indicator">
                <svg viewBox="0 0 1024 1024" width="12" height="12">
                  <path
                    d="M340 836H140c-6.6 0-12-5.4-12-12V624c0-6.6 5.4-12 12-12h200c6.6 0 12 5.4 12 12v200c0 6.6-5.4 12-12 12zm544 0H684c-6.6 0-12-5.4-12-12V624c0-6.6 5.4-12 12-12h200c6.6 0 12 5.4 12 12v200c0 6.6-5.4 12-12 12zm-544-544H140c-6.6 0-12-5.4-12-12V80c0-6.6 5.4-12 12-12h200c6.6 0 12 5.4 12 12v200c0 6.6-5.4 12-12 12zm544 0H684c-6.6 0-12-5.4-12-12V80c0-6.6 5.4-12 12-12h200c6.6 0 12 5.4 12 12v200c0 6.6-5.4 12-12 12z"
                    fill="currentColor"
                  />
                </svg>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
  .panel-container {
    height: 100%;
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  }

  .panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
    border-radius: 8px 8px 0 0;

    .header-title {
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 13px;
      font-weight: 600;
      color: #262626;
      margin-bottom: 2px;

      .header-icon {
        color: #1890ff;
        flex-shrink: 0;
        width: 14px;
        height: 14px;
      }
    }

    .header-subtitle {
      font-size: 11px;
      color: #8c8c8c;
      line-height: 1.4;
    }
  }

  .panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 6px;

    &::-webkit-scrollbar {
      width: 3px;
    }

    &::-webkit-scrollbar-track {
      background: #f5f5f5;
      border-radius: 2px;
    }

    &::-webkit-scrollbar-thumb {
      background: #d9d9d9;
      border-radius: 2px;

      &:hover {
        background: #bfbfbf;
      }
    }
  }

  .node-category {
    .category-title {
      font-size: 11px;
      font-weight: 600;
      color: #8c8c8c;
      text-transform: uppercase;
      letter-spacing: 0.3px;
      margin-bottom: 8px;
      padding: 0 6px;
    }
  }

  .node-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .node-item {
    cursor: grab;
    user-select: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    &:hover {
      transform: translateY(-1px);
      .drag-indicator {
        opacity: 1;
      }
    }

    &:active {
      cursor: grabbing;
      transform: translateY(0) scale(0.98);
    }
  }

  .node-card {
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
  }

  .node-icon-wrapper {
    flex-shrink: 0;
  }

  .node-icon {
    width: 38px;
    height: 38px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
    border: 1px solid rgba(0, 0, 0, 0.06);
  }

  .node-content {
    flex: 1;
    min-width: 0;
  }

  .node-title {
    font-size: 14px;
    font-weight: 500;
    color: #262626;
    line-height: 1.3;
    margin-bottom: 5px;
  }

  .node-desc {
    font-size: 10px;
    color: #8c8c8c;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .drag-indicator {
    opacity: 0;
    color: #bfbfbf;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
    padding: 1px;
    svg {
      width: 10px;
      height: 10px;
    }
  }
  // 响应式设计
  @media (max-width: 1400px) {
    .panel-header {
      padding: 10px 12px;
    }
    .panel-content {
      padding: 6px 4px;
    }
    .node-card {
      padding: 6px 8px;
      gap: 6px;
    }
    .node-icon {
      width: 24px;
      height: 24px;
      font-size: 12px;
    }
    .node-title {
      font-size: 11px;
    }
    .node-desc {
      font-size: 9px;
    }
  }

  @media (max-width: 1200px) {
    .panel-container {
      border-radius: 4px;
    }

    .panel-header {
      padding: 8px 10px;
      border-radius: 4px 4px 0 0;
    }

    .panel-content {
      padding: 4px 2px;
    }

    .node-list {
      gap: 4px;
    }

    .node-card {
      padding: 5px 6px;
      gap: 5px;
      border-radius: 3px;
    }

    .node-icon {
      width: 20px;
      height: 20px;
      font-size: 10px;
      border-radius: 3px;
    }

    .category-title {
      font-size: 10px;
      margin-bottom: 6px;
      padding: 0 4px;
    }
  }
</style>
